﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BYManageInfoSystem
{
    public partial class Frm_TTFeeDetail : Form
    {
        private int m_nSelectId = 0;

        private DGBY.BLL.FeeTTLoanAndFeeRegDetailInfoTab m_bllFeeTTLoanAndFeeRegDetailInfoTab = new DGBY.BLL.FeeTTLoanAndFeeRegDetailInfoTab();

        public Frm_TTFeeDetail()
        {
            InitializeComponent();
        }

        public Frm_TTFeeDetail(int nSelectID)
        {
            InitializeComponent();
       
            m_nSelectId = nSelectID;
        }

        private void ShowAllRecord()
        {
            dataGridView1.DataSource = null;
            DataSet ds = m_bllFeeTTLoanAndFeeRegDetailInfoTab.GetTTRecvMoneyDetailInfoList("FeeTTLoanAndFeeRegDetailInfoTab.FeeTTLoanAndFeeRegDetailInfoTabID = '"
                                                                                     + m_nSelectId.ToString() + "'");

            string strTempNote1 = ds.Tables[0].Rows[0]["出口议付审单费备注"].ToString();
            string strTempNote2 = ds.Tables[0].Rows[0]["快递费备注"].ToString();
            string strTempNote3 = ds.Tables[0].Rows[0]["通知费备注"].ToString();
            string strTempNote4 = ds.Tables[0].Rows[0]["其他费备注"].ToString();
            Decimal dt1 = Convert.ToDecimal(ds.Tables[0].Rows[0]["出口议付审单费"].ToString());
            Decimal dt2 = Convert.ToDecimal(ds.Tables[0].Rows[0]["快递费"].ToString());
            Decimal dt3 = Convert.ToDecimal(ds.Tables[0].Rows[0]["通知费"].ToString());
            Decimal dt4 = Convert.ToDecimal(ds.Tables[0].Rows[0]["其他费"].ToString());
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dtNew = new DataTable();

                dtNew.Columns.Add("国内扣费", System.Type.GetType("System.String"));
                dtNew.Columns.Add("金额", System.Type.GetType("System.Decimal"));
                dtNew.Columns.Add("备注", System.Type.GetType("System.String"));

                DataRow objRow;

                objRow = dtNew.NewRow();

                objRow[0] = "出口议付审单费";
                objRow[1] = dt1;
                objRow[2] = strTempNote1;

                dtNew.Rows.Add(objRow);



                objRow = dtNew.NewRow();

                objRow[0] = "快递费";
                objRow[1] = dt2;
                objRow[2] = strTempNote2;

                dtNew.Rows.Add(objRow);



                objRow = dtNew.NewRow();

                objRow[0] = "通知费";
                objRow[1] = dt3;
                objRow[2] = strTempNote3;

                dtNew.Rows.Add(objRow);



                objRow = dtNew.NewRow();

                objRow[0] = "其他费";
                objRow[1] = dt4;
                objRow[2] = strTempNote4;

                dtNew.Rows.Add(objRow);

   

                objRow = dtNew.NewRow();

                objRow[0] = "合计";
                objRow[1] = dt4 + dt1 + dt2 + dt3;
                objRow[2] = "";

                dtNew.Rows.Add(objRow);

                dataGridView1.DataSource = dtNew;
            }

        }

        private void Frm_TTFeeDetail_Load(object sender, EventArgs e)
        {
            ShowAllRecord();
        }

        private void buttonModify_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.FeeTTLoanAndFeeRegDetailInfoTab modelFeeTTLoanAndFeeRegDetailInfoTab = m_bllFeeTTLoanAndFeeRegDetailInfoTab.GetModel(m_nSelectId);
                if (modelFeeTTLoanAndFeeRegDetailInfoTab == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                int nIndex = this.dataGridView1.CurrentCell.RowIndex;
                switch (nIndex)
                {
                    case 0:
                        {
                            modelFeeTTLoanAndFeeRegDetailInfoTab.ChuKouNote = this.textBoxNote.Text;
                            break;
                        }
                    case 1:
                        {
                            modelFeeTTLoanAndFeeRegDetailInfoTab.KuaiDiNote = this.textBoxNote.Text;
                            break;
                        }
                    case 2:
                        {
                            modelFeeTTLoanAndFeeRegDetailInfoTab.NotifyNote = this.textBoxNote.Text;
                            break;
                        }
                    case 3:
                        {
                            modelFeeTTLoanAndFeeRegDetailInfoTab.OtherNote = this.textBoxNote.Text;
                            break;
                        }
                    default:
                        break;
                }


                m_bllFeeTTLoanAndFeeRegDetailInfoTab.Update(modelFeeTTLoanAndFeeRegDetailInfoTab);
                ShowAllRecord();
                MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (this.dataGridView1.CurrentCell.RowIndex > 3)
                return;
            this.textBoxNote.Text = this.dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            {
                if (e.RowIndex > 3)
                    return;
                using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
                {
                    e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
                }
            }
        }
    }
}
